package cn.one.ball.controller;

import cn.one.ball.entity.Banner;
import cn.one.ball.entity.Player;
import cn.one.ball.mapper.BannerMapper;
import cn.one.ball.mapper.PlayerMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/player/")
public class PlayerController {
    @Autowired(required = false)
    PlayerMapper mapper;
    @RequestMapping("select")
    public List<Player> select(){
        return mapper.select();
    }
    @RequestMapping("delete")
    public void delete(int id){
        Player player = mapper.selectById(id);
        new File("d:/files"+player.getUrl()).delete();
    }
    @RequestMapping("insert")
    public void insert(@RequestBody Player player){
        System.out.println("player" + player);
        mapper.insert(player);
    }
    @RequestMapping("selectById")
    public Player selectById(int id){
        return mapper.selectById(id);
    }
    @RequestMapping("update")

    public void update(@RequestBody Player player){
        Player oldPlayer = mapper.selectById(player.getId());
        //删除原来的图片文件
        new File("d:/files"+oldPlayer.getUrl()).delete();
        mapper.update(player);
    }
}
